home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
parallax
/
more_exa.tar
/
more
/
sim_ann.p
< prev
Wrap
Text File
|
1991-11-26
|
19KB
|
548 lines
SYSTEM Chip_Placement;
(*--------------------------------------------------------------------------------*)
CONST root_n=3; n=root_n**2;
histogram_treshold = 2;
(* n : number of chips on board *)
(* histogram_treshold : *)
(* max number of wires, which found place between two chips without *)
(* overcramming the board at this place *)
(*--------------------------------------------------------------------------------*)
TYPE smallset = SET OF [1..n];
feld1 = ARRAY [1..n] OF BOOLEAN;
feld2 = ARRAY [1..n] OF INTEGER;
(*--------------------------------------------------------------------------------*)
CONFIGURATION grid [root_n],[root_n];
CONNECTION sright: grid[i,j] -> grid[i ,(j+1) MOD root_n].sleft;
sleft : grid[i,j] -> grid[i ,(j-1) MOD root_n].sright;
sup : grid[i,j] -> grid[(i+1) MOD root_n, j ].sdown;
sdown : grid[i,j] -> grid[(i-1) MOD root_n, j ].sup;
(* Configuration and Connection defining a two-dimensioned torus with sidelength *)
(* root_n *)
(*--------------------------------------------------------------------------------*)
SCALAR net_table : ARRAY [1..n] OF feld1;
x_coord_table, y_coord_table : ARRAY [1..n] OF feld2;
chip_nr_list : feld2;
(* net_table contains connections between chips *)
(* net_table(i,j)=TRUE <=> there's a connection from chip i to chip j *)
(* x_coord_table and y_coord_table contains X- and Y-coordinates of chips *)
(* X-coordinate(Chip i)=x_coord_table[k,i]; k=1..n *)
(* Y-coordinate(Chip j)=y_coord_table[k,i]; k=1..n *)
(* chip_nr_list contains the assignments from chip to PE. *)
(* Chip i is assigned to PE chip_nr_list[i] *)
(*--------------------------------------------------------------------------------*)
VECTOR net_list : feld1;
x_coord_list, y_coord_list : feld2;
chip_nr : INTEGER;
(* These are the analogue vector-varaibles to the scalar-variables above. *)
(* They would be used for initializing vectors and exchanging datas between two *)
(* vectors *)
(*--------------------------------------------------------------------------------*)
PROCEDURE Init;
(* initializing variables with start-values *)
SCALAR net_set : ARRAY [1..n] OF smallset;
i,j : INTEGER;
(* The array net_set would be used only for easyer data-assignment. The net_set's *)
(* would be used for building the net_table. *)
VECTOR v : INTEGER;
BEGIN
net_set[ 1]:=smallset{3,4,5,6,7,8,9};
net_set[ 2]:=smallset{1,4,5,6,7,8,9};
net_set[ 3]:=smallset{1,2,5,6,7,8,9};
net_set[ 4]:=smallset{1,2,3,6,7,8,9};
net_set[ 5]:=smallset{1,2,3,4,7,8,9};
net_set[ 6]:=smallset{1,2,3,4,5,8,9};
net_set[ 7]:=smallset{1,2,3,4,6,8,9};
net_set[ 8]:=smallset{1,2,3,4,5,7,9};
net_set[ 9]:=smallset{2,3,4,5,6,7,8};
(*
net_set[10]:=smallset{11,16};
net_set[11]:=smallset{12,17};
net_set[12]:=smallset{18};
net_set[13]:=smallset{14,19};
net_set[14]:=smallset{15,20};
net_set[15]:=smallset{16,21};
net_set[16]:=smallset{17,22};
net_set[17]:=smallset{18,23};
net_set[18]:=smallset{24};
net_set[19]:=smallset{20,25};
net_set[20]:=smallset{21,26};
net_set[21]:=smallset{22,27};
net_set[22]:=smallset{23,28};
net_set[23]:=smallset{24,29};
net_set[24]:=smallset{30};
net_set[25]:=smallset{26,31};
net_set[26]:=smallset{27,32};
net_set[27]:=smallset{28,33};
net_set[28]:=smallset{29,34};
net_set[29]:=smallset{30,35};
net_set[30]:=smallset{36};
net_set[31]:=smallset{32};
net_set[32]:=smallset{33};
net_set[33]:=smallset{34};
net_set[34]:=smallset{35};
net_set[35]:=smallset{36};
net_set[36]:=smallset{};
*)
(* For wiring example one 6*6 Array of chips. Each chip has a connection to *)
(* it's right and above neighbour (if it has one) *)
(* building net_table out of net_setn: *)
FOR i:=1 TO n DO
FOR j:=1 TO n DO
IF j IN net_set[i] THEN net_table[i,j]:=TRUE
ELSE net_table[i,j]:=FALSE END;
END;
END;
LOAD(net_list,net_table);
(* building x_coord_list and y_coord_list. The assignment is resulting from *)
(* regular construction on board *)
PARALLEL
FOR v:=1 TO n DO
x_coord_list[v]:=(v-1) MOD root_n+1;
y_coord_list[v]:=(v-1) DIV root_n+1;
END;
ENDPARALLEL;
STORE(x_coord_list,x_coord_table);
STORE(y_coord_list,y_coord_table);
(* building chip_nr_list. At the beginning chip i is assigned to PE i : *)
FOR i:=1 TO n DO
chip_nr_list[i]:=i
END;
LOAD(chip_nr,chip_nr_list);
END Init;
(*--------------------------------------------------------------------------------*)
PROCEDURE write_connection;
(* This procedure displays clear which chip connected to which other chip. *)
SCALAR i,j : INTEGER;
leere_liste : BOOLEAN;
BEGIN
FOR i:=1 TO n DO
leere_liste:=TRUE;
WriteString('Chip[');WriteInt(i,1);WriteString('] is connected to: ');
FOR j:=1 TO n DO
IF net_table[i,j]=TRUE THEN leere_liste:=FALSE;
WriteInt(j,1);WriteString(', ') END;
END;
IF leere_liste=TRUE THEN WriteString(' nobody') END;
WriteLn;
END;
END write_connection;
(*--------------------------------------------------------------------------------*)
PROCEDURE Write_coordinates;
(* This procedure displays the coordinates of the chips *)
SCALAR i : INTEGER;
BEGIN
FOR i:=1 TO n DO
WriteString('Chip[');WriteInt(i,1);WriteString('] X-Coord.: ');
WriteInt(x_coord_table[1,i],3);
WriteString(', Y-Koord.: ');
WriteInt(y_coord_table[1,i],3);
WriteLn;
END;
END Write_coordinates;
(*--------------------------------------------------------------------------------*)
PROCEDURE Display_Chips;
(* Output of this procedure is the graphical representation of the chips. *)
SCALAR i,j : INTEGER;
display : ARRAY [1..root_n],[1..root_n] OF INTEGER;
BEGIN
FOR i:=1 TO n DO
display[x_coord_table[1,i],y_coord_table[1,i]]:=i
END;
FOR i:=root_n TO 1 BY -1 DO
FOR j:=1 TO root_n DO
WriteInt(display[j,i],6);
END;
WriteLn;
WriteLn;
END;
END Display_Chips;
(*--------------------------------------------------------------------------------*)
PROCEDURE exchange_chips(SCALAR i,j : INTEGER);
(* This procedure exchanges chip i with chip j . *)
SCALAR k,help1, help2 : INTEGER;
help3 : BOOLEAN;
BEGIN
(* exchange column i with column j in x_coord_table and y_coord_table *)
FOR k:=1 TO n DO
help1:=x_coord_table[k,i];
x_coord_table[k,i]:=x_coord_table[k,j];
x_coord_table[k,j]:=help1;
END;
LOAD [*],[*] (x_coord_list,x_coord_table);
FOR k:=1 TO n DO
help1:=y_coord_table[k,i];
y_coord_table[k,i]:=y_coord_table[k,j];
y_coord_table[k,j]:=help1;
END;
LOAD [*],[*] (y_coord_list,y_coord_table);
(* find out, which PE is assigned to chip i : PE help 1, *)
(* and which PE is assigned to chip j : PE help 2. *)
FOR k:=1 TO n DO
IF chip_nr_list[k] = i THEN help1:=k END;
IF chip_nr_list[k] = j THEN help2:=k END;
END;
(* exchange line help1 with line help2 in net_table *)
FOR k:=1 TO n DO
help3:=net_table[help1,k];
net_table[help1,k]:=net_table[help2,k];
net_table[help2,k]:=help3;
END;
LOAD(net_list,net_table);
(* exchange entry help1 with entry help2 in chip_nr_list *)
chip_nr_list[help1]:=j;
chip_nr_list[help2]:=i;
LOAD(chip_nr,chip_nr_list);
END exchange_chips;
(*--------------------------------------------------------------------------------*)
PROCEDURE compute_energie(): SCALAR REAL;
(* This procedure calculates the energie E=l+lambda*u *)
CONST lambda = 1.0;
(* lambda : proportionality factor. *)
SCALAR x_length, y_length : INTEGER;
histogram_total : INTEGER;
i,j : INTEGER;
up_scalar, down_scalar : ARRAY [1..root_n],[1..root_n] OF INTEGER;
right_scalar, left_scalar : ARRAY [1..root_n],[1..root_n] OF INTEGER;
vert_histogram, hori_histogram : ARRAY[1..root_n-1] OF INTEGER;
(* x_length and y_length contains total X- resp. Y-Length of lands *)
(* histogram_total correspnds to over-filling u. *)
(* i,j running variables. *)
(* right_scalar, left_scalar, up_scalar and down_scalar are required for *)
(* calculating of histograms. *)
(* vert_histogram and hori_histogram contains the entrys of vertical resp. *)
(* horizontal histograms. *)
VECTOR x_min, x_max, y_min, y_max, x_gesamt, y_gesamt : INTEGER;
help_x, help_y : INTEGER;
left, right, up, down : INTEGER;
v : INTEGER;
(* x_min, x_max, y_min and y_max contains the size of rectangles for *)
(* calculating over-filling. *)
(* help_x and help_y are helping variables. *)
(* left, right, up, down analogue to scalar-variables of the same name *)
(* v is running variable. *)
BEGIN
(* find out for each chip in Net_List this chip, which: *)
(* - stand most distant over it -> x_max *)
(* - stand most distant under it -> x_min *)
(* - stand most distant left it -> y_max *)
(* - stand most distant right it -> y_min *)
PARALLEL
x_min:=0; x_max:=0; y_min:=0; y_max:=0; help_x:=0; help_y:=0;
FOR i:=1 TO n DO
IF net_list[i] = TRUE THEN
help_x:=x_coord_list[i]-x_coord_list[chip_nr];
help_y:=y_coord_list[i]-y_coord_list[chip_nr];
IF help_x > x_max THEN x_max:=help_x; END;
IF help_x < x_min THEN x_min:=help_x; END;
IF help_y > y_max THEN y_max:=help_y; END;
IF help_y < y_min THEN y_min:=help_y; END;
END;
END;
(* calculating total X- resp. Y-Length of each rectangle: *)
x_gesamt:=x_max-x_min;
y_gesamt:=y_max-y_min
ENDPARALLEL;
(* calculating total X- resp. Y-Length of wiring: *)
x_length:=REDUCE.SUM(x_gesamt);
y_length:=REDUCE.SUM(y_gesamt);
(* x_max, x_min,.. would be assigned to right, left,.. in a way, so that *)
(* histogram-entrys can be calculated : *)
PARALLEL
left:=0; right:=0; up:=0; down:=0;
FOR v:=1 TO root_n-1 DO
IF y_max > 0 THEN up:=up+1; y_max:=y_max-1 END;
IF y_min < 0 THEN down:=down+1; y_min:=y_min+1 END;
IF x_max > 0 THEN right:=right+1; x_max:=x_max-1 END;
IF x_min < 0 THEN left:=left+1; x_min:=x_min+1 END;
PROPAGATE.sup(y_max);
PROPAGATE.sdown(y_min);
PROPAGATE.sright(x_max);
PROPAGATE.sleft(x_min);
END;
ENDPARALLEL;
STORE(up,up_scalar);
STORE(down,down_scalar);
STORE(left,left_scalar);
STORE(right,right_scalar);
(* The single histogram-entrys would be calculated out of the arrays up, down, *)
(* right and left : *)
FOR i:=1 TO root_n-1 DO
vert_histogram[i]:=0; hori_histogram[i]:=0;
FOR j:= 1 TO root_n DO
vert_histogram[i]:=vert_histogram[i]+right_scalar[j,i]+left_scalar[j,i+1];
hori_histogram[i]:=hori_histogram[i]+down_scalar[i+1,j]+up_scalar[i,j];
END;
END;
(* The single histogram-entrys have to be summarized to a total function : *)
histogram_total:=0;
FOR i:=1 TO root_n-1 DO
IF vert_histogram[i] > histogram_treshold
THEN vert_histogram[i]:=vert_histogram[i]-histogram_treshold
ELSE vert_histogram[i]:=0 END;
IF hori_histogram[i] > histogram_treshold
THEN hori_histogram[i]:=hori_histogram[i]-histogram_treshold
ELSE hori_histogram[i]:=0 END;
histogram_total:=histogram_total+vert_histogram[i]**2+hori_histogram[i]**2;
END;
RETURN(FLOAT(x_length+y_length)+(lambda*FLOAT(histogram_total)));
END compute_energie;
(*--------------------------------------------------------------------------------*)
PROCEDURE Annealing;
CONST n_max = TRUNC(FLOAT(n*(n-1))*.5);
t_null = 0.001;
delta_t = 0.001;
c_t = 0.98;
a_s = 0.75;
a_k = 0.1;
t_min = 0.001;
max_error = 120;
SCALAR e_new, e_old, delta_e, e_sum, a, b : REAL;
t : REAL;
misattempt : INTEGER;
counter, num_accept_states : INTEGER;
i,j : INTEGER;
BEGIN
WriteString(' M E L T I N G - P H A S E ');
WriteLn;WriteLn;WriteLn;
WriteString('Source wiring:');
WriteLn;WriteLn;
Display_Chips;
WriteLn;WriteLn;
WriteString('Start-temperature (t_min) = ');WriteReal(t_null,10);WriteLn;
WriteString('Temperature raising const.(delta_t) = ');WriteReal(delta_t,10);WriteLn;
WriteString('Number sequential states (n_max) = ');WriteInt(n_max,10);WriteLn;
WriteLn;
WriteString('Start energie: ');
WriteReal(compute_energie(),10);
WriteLn;WriteLn;
t:=t_null;
e_old:=compute_energie();
REPEAT
counter:=0;
e_sum:=0.0;
t:=t+delta_t;
WriteString('New temperature: ');WriteReal(t,15);WriteLn;WriteLn;WriteLn;
num_accept_states:=0;
REPEAT
REPEAT
i:=SIRandom() MOD n +1;
j:=SIRandom() MOD n +1;
UNTIL i<>j;
counter:=counter+1;
exchange_chips(i,j);
e_new:=compute_energie();
e_sum:=e_sum+e_new;
delta_e:=e_new-e_old;
IF delta_e <= 0.0 THEN e_old:=e_new;
num_accept_states:=num_accept_states+1 END;
IF delta_e > 0.0 THEN IF (-delta_e/t) < -700.0 THEN a:=0.0
ELSE a:=Exp(-delta_e/t) END;
(* it's neccessary to check "< 700", because PARZ-Simulator generate error - *)
(* message on values less than exp(-700). *)
b:=SRRandom();
IF a > b THEN
e_old:=e_new;
num_accept_states:=num_accept_states+1;
ELSE exchange_chips(j,i) END;
END;
UNTIL( FLOAT(num_accept_states) >= a_s*FLOAT(n_max)) OR (counter = n_max);
WriteString('Temperature: '); WriteReal(t,10); WriteLn;
WriteInt(num_accept_states,5);
WriteString(' States of ');
WriteInt(counter,5);
WriteString(' attempts were accepted with this temperature');WriteLn;
WriteString('Average energie: ');WriteReal(e_sum/FLOAT(counter),10);
WriteLn;
Display_Chips;
WriteLn;
UNTIL FLOAT(num_accept_states) >= a_s*FLOAT(n_max);
WriteString('** Melting phase finished');
WriteLn;WriteLn;
e_old:=compute_energie();
WriteString('Chip configuration:');
WriteLn;WriteLn;
Display_Chips;
WriteLn;WriteLn;
WriteString('Temperature: ');WriteReal(t,10);
WriteString('System energie: ');WriteReal(e_old,10);
WriteLn;WriteLn;
(* WriteInt(num_accept_states,5);
WriteString(' States of ');
WriteInt(counter,5);
WriteString(' attempts were accepted with this temperature');
*)
WriteLn;WriteLn;
WriteString(' C O O L I N G - P H A S E ');
WriteLn;WriteLn;
misattempt:=0;
REPEAT
counter:=0;
t:=t*c_t;
WriteString('New temperature: ');WriteReal(t,15);WriteLn;WriteLn;WriteLn;
num_accept_states:=0;
e_sum:=0.0;
REPEAT
REPEAT
i:=SIRandom() MOD n +1;
j:=SIRandom() MOD n +1;
UNTIL i<>j;
exchange_chips(i,j);
counter:=counter+1;
e_new:=compute_energie();
e_sum:=e_sum+e_new;
delta_e:=e_new-e_old;
IF delta_e <= 0.0 THEN e_old:=e_new;
num_accept_states:=num_accept_states+1 END;
IF delta_e > 0.0 THEN IF (-delta_e/t) < -700.0 THEN a:=0.0
ELSE a:=Exp(-delta_e/t) END;
(* it's neccessary to check "< 700", because PARZ-Simulator generate error - *)
(* message on values less than exp(-700). *)
b:=SRRandom();
IF a > b THEN
e_old:=e_new;
num_accept_states:=num_accept_states+1;
ELSE exchange_chips(j,i) END;
END;
UNTIL( FLOAT(num_accept_states) >= a_k*FLOAT(n_max)) OR (counter = n_max);
IF FLOAT(num_accept_states) <= a_k*FLOAT(n) THEN misattempt:=misattempt+1
ELSE misattempt:=0 END;
(*
WriteString('Temperature: '); WriteReal(t,10); WriteLn;
WriteInt(num_accept_states,5);
WriteString(' States of ');
WriteInt(counter,5);
WriteString(' attempts were accepted with this temperature');WriteLn;
WriteString('Average energie: ');WriteReal(e_sum/FLOAT(counter),10);
WriteLn;
Display_Chips;
WriteLn;
*)
UNTIL (t < t_min) OR (misattempt > max_error) OR (num_accept_states = 0);
WriteString('** Coolong phase finished');
WriteString('Minimized wiring:');WriteLn;
Display_Chips; WriteLn;
WriteString('System energie: ');WriteReal(e_old,10);WriteLn;
END Annealing;
BEGIN
WriteString('SIMULATION REPORT');WriteLn;WriteLn;
Init;
write_connection;
Write_coordinates;
Annealing;
END Chip_Placement.